package com.crm.service.Impl;

import com.crm.mapper.goodsMapper;
import com.crm.pojo.Goods;
import com.crm.pojo.client;
import com.crm.pojo.pageBean;
import com.crm.service.goodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class goodsServiceImpl implements goodsService {
    @Autowired
    private goodsMapper mapper;

    @Override
    public List<Goods> queryAll() {
        return mapper.selectAll();
    }

    @Override
    public pageBean<Goods> selectByPage( Integer currentPage, Integer pageSize) {
        //计算开始索引
        int currentPage1 = (currentPage - 1)*pageSize;
        List<Goods> goodsList = mapper.selectAll();
        List<Goods> pageList = mapper.selectByPage(currentPage1, pageSize);
        pageBean pageBean = new pageBean();
        pageBean.setRows(pageList);
        pageBean.setTotalCount(goodsList.size());
        return pageBean;

    }

    @Override
    public Goods queryOne(int id) {
        return mapper.selectById(id);
    }

    @Override
    public boolean save(Goods goods) {
        return mapper.addGoods(goods);
    }

    @Override
    public boolean update(Goods goods) {
        return mapper.updateGoods(goods);
    }

    @Override
    public boolean removeOne(int id) {
        return mapper.deleteGoods(id);
    }
}
